#
# MASTER INFORMATION SYSTEMS CORPORATION
# Copyright (C) 1996. All Right Reserved.
#

#
# MUSKOX install.sh script
#

#
# install headers, engine, and framework files in the examples directory
# then install mskx executable
#

TARGET=""
MSKXTARGET="/opt/muskox12"
while [ "$TARGET" = "" ]
do
	echo "
Enter a directory name (absolute path!) to install MUSKOX (\"$MSKXTARGET\" default):"
	read TARGET
	TARGET=`eval echo "$TARGET"`
	if [ "$TARGET" = "" ]
	then
		TARGET=$MSKXTARGET
	fi
	if [ ! -d "$TARGET" ]
	then
		if [ -f "$TARGET" ]
		then
			echo "
WARNING: File called \"$TARGET\" already exists."
			TARGET = ""
			continue
		fi
		mkdir -p $TARGET 2>/dev/null
		if [ $? -ne 0 ]
		then
			echo "
WARNING: Can't create \"$TARGET\" directory."
			TARGET=""
			continue;
		fi
	fi
	if [ "$TARGET" != "" ]; then
		touch $TARGET/bla 2>/dev/null
		if [ ! -f $TARGET/bla ]; then
			echo "
WARNING: Can't create files in $TARGET."
			TARGET=""
		else
			rm $TARGET/bla
		fi
	fi
done
MSKXTARGET=$TARGET
echo "Uncompressing..."
uncompress -c MUSKOX.TAR.Z > $MSKXTARGET/MUSKOX.TAR
if [ $? -ne 0 ]; then
	echo "
 ERROR: uncompress failed, installation aborted."
	exit 1
fi
cd $MSKXTARGET
if [ -d muskox ]
then
	echo "
Removing all preexisting muskox files from $MSKXTARGET/muskox..."
	rm -r muskox
	if [ -d muskox ]
	then
		echo "
 ERROR: Cannot remove preexisting muskox files from $MSKXTARGET/muskox, 
 installation aborted."
		exit 1;
	fi
fi
echo "Extracting files..."
tar xf MUSKOX.TAR
rm -f MUSKOX.TAR
echo "Linking headers..."
cd muskox
ln -s $MSKXTARGET/muskox/headers/atribus.h   $MSKXTARGET/muskox/examples/atribus.h
ln -s $MSKXTARGET/muskox/headers/bml.h       $MSKXTARGET/muskox/examples/bml.h
ln -s $MSKXTARGET/muskox/headers/generus.h   $MSKXTARGET/muskox/examples/generus.h
ln -s $MSKXTARGET/muskox/headers/inpus.h     $MSKXTARGET/muskox/examples/inpus.h
ln -s $MSKXTARGET/muskox/headers/nodus.h     $MSKXTARGET/muskox/examples/nodus.h
ln -s $MSKXTARGET/muskox/headers/pc.h        $MSKXTARGET/muskox/examples/pc.h
ln -s $MSKXTARGET/muskox/headers/skelbmon.h  $MSKXTARGET/muskox/examples/skelbmon.h
ln -s $MSKXTARGET/muskox/headers/skeletus.h  $MSKXTARGET/muskox/examples/skeletus.h

echo "Linking engine..."
ln -s $MSKXTARGET/muskox/engine/generus.cpp  $MSKXTARGET/muskox/examples/generus.cpp
ln -s $MSKXTARGET/muskox/engine/inpus.cpp    $MSKXTARGET/muskox/examples/inpus.cpp
ln -s $MSKXTARGET/muskox/engine/skeletus.cpp $MSKXTARGET/muskox/examples/skeletus.cpp
ln -s $MSKXTARGET/muskox/engine/skelbmon.cpp $MSKXTARGET/muskox/examples/skelbmon.cpp

echo "Linking framework..."
ln -s $MSKXTARGET/muskox/framework/pc.cpp    $MSKXTARGET/muskox/examples/pc.cpp
ln -s $MSKXTARGET/muskox/framework/nodus.cpp $MSKXTARGET/muskox/examples/nodus.cpp

echo "Linking mskx executable..."
ln -s $MSKXTARGET/muskox/mskx                $MSKXTARGET/muskox/examples/mskx
echo "Show expiration day..."
$MSKXTARGET/muskox/mskx
echo "
*** MUSKOX installed in $MSKXTARGET."
